<<<<<<< HEAD
import React from "react"
import { Link } from "umi";
import { Layout, Menu, Dropdown, Avatar, Button } from 'antd';
import { UserOutlined, LaptopOutlined, NotificationOutlined, DownOutlined } from '@ant-design/icons';
// 引入国际化
import { useIntl, getLocale, setLocale, useSelector } from 'umi';
import { IMenu } from '../../utils/interface';
import style from "./_layout.less"
const { SubMenu } = Menu;
const { Header, Content, Sider } = Layout;
const MainLayot: React.FC = (props) => {
    const intl = useIntl();
    // const { userMenu }: { userMenu: IMenu[] } = useSelector(models =>module.user);

    const menu = (
        <Menu>
            <Menu.Item>
                <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
                    个人中心
            </a>
            </Menu.Item>
            <Menu.Item>
                <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
                    我的班级
            </a>
            </Menu.Item>
            <Menu.Item>
                <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
                    设置
            </a>
            </Menu.Item>
            <Menu.Item danger>退出登录</Menu.Item>
        </Menu>
    )


    function changeLocale() {        
        let locale = getLocale();
        if (locale === 'zh-CN') {
            setLocale('en-US', false);
        } else {
            setLocale('zh-CN', false);
        }
    }
    // 处理默认选中和展开菜单
    // let defaultOpenKeys = userMenu.length ? [userMenu[0].name] : [];
    // let defaultSelectedKeys = userMenu.length ? [userMenu[0].children![0].name] : [];
    // console.log('default...', defaultOpenKeys, defaultSelectedKeys);
    return (
        <Layout>
            <Header className={"header style.header"}>
                <h2>
                    <img className={style._layoutimg} src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1551624718911&di=4a7004f8d71bd8da84d4eadf1b59e689&imgtype=0&src=http%3A%2F%2Fimg105.job1001.com%2Fupload%2Falbum%2F2014-10-15%2F1413365052_95IE3msH.jpg" alt="" />
                </h2>
                <Button onClick={changeLocale}>{getLocale() === 'zh-CN' ? '英文' : '中文'}</Button>
                <Dropdown overlay={menu}>
                    <div>
                        <Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />
                        <span>xiaojinzhe</span>
                    </div>
                </Dropdown>
            </Header>
            <Layout>
                <Sider width={200} className="site-layout-background">
                    <Menu
                        // mode="inline"
                        theme="dark"
                        defaultSelectedKeys={['0']}
                        defaultOpenKeys={['sub1']}
                        // defaultOpenKeys={defaultOpenKeys}
                        // defaultSelectedKeys={defaultSelectedKeys}
                        style={{ height: '100%', borderRight: 0 }}
                    >
                        {/* {
                            userMenu.map((item: any) => {
                                return <SubMenu key={item.name} icon={<item.meta.icon />} title={intl.formatMessage({ id: item.name })}>{
                                    item.children?.map((value:any) => {
                                        return value.meta.show ? <Menu.Item key={value.name}>
                                            <Link to={value.path}>{intl.formatMessage({ id: value.name })}</Link>
                                        </Menu.Item> : null
                                    })
                                }</SubMenu>
                            })
                        } */}
                        <SubMenu key="sub1" icon={<UserOutlined />} title="试题管理">
                            
                            <Menu.Item key="1">
                                <Link to="/main/addQuestions">添加试题</Link>
                            </Menu.Item>
                            <Menu.Item key="2">
                                <Link to="/main/questionTypes">试题分类</Link>
                            </Menu.Item>
                            <Menu.Item key="3">
                                <Link to="/main/watchQuestions">查看试题</Link>
                            </Menu.Item>
                        </SubMenu>
                        <SubMenu key="sub2" icon={<LaptopOutlined />} title="用户管理">
                            <Menu.Item key="5">
                                <Link to="/main/addUser">添加用户</Link>
                            </Menu.Item>
                            <Menu.Item key="6">
                                <Link to="/main/userDisplay">用户展示</Link>
                            </Menu.Item>
                        </SubMenu>
                        <SubMenu key="sub3" icon={<NotificationOutlined />} title="考试管理">
                            <Menu.Item key="7">
                                <Link to="/main/AddTheTest">添加考试</Link>
                            </Menu.Item>
                            <Menu.Item key="8">
                                <Link to="/main/ItemList">试题列表</Link>
                            </Menu.Item>
                        </SubMenu>
                        <SubMenu key="sub4" icon={<NotificationOutlined />} title="班级管理">
                            <Menu.Item key="9">
                                <Link to="/main/classManagement">班级管理</Link>
                            </Menu.Item>
                            <Menu.Item key="10">
                                <Link to="/main/ClassroomManagement">教室管理</Link>
                            </Menu.Item>
                            <Menu.Item key="11">
                                <Link to="/main/StudnetManagement">学生管理</Link>
                            </Menu.Item>
                        </SubMenu>
                        <SubMenu key="sub5" icon={<NotificationOutlined />} title="阅卷管理">
                            <Menu.Item key="12">
                                <Link to="/main/addExam">添加考试</Link>
                            </Menu.Item>
                        </SubMenu>
                    </Menu>
                </Sider>
                <Layout style={{ padding: '0 24px 24px' }}>
                    <Content
                        className="site-layout-background"
                        style={{
                            padding: 24,
                            margin: 0,
                            minHeight: 280,
                        }}
                    >
                        {props.children}
                    </Content>
                </Layout>
            </Layout>
=======
import React from 'react'
import { Link, useSelector, useIntl, getLocale, setLocale, } from 'umi'
import { Layout, Menu, Dropdown, Avatar, Image, Button } from 'antd';
import styles from './_layout.less';
import { IMenu } from '@/utils/interface';

const { SubMenu } = Menu;
const { Header, Content, Sider } = Layout;
const MainLayout: React.FC = (props) => {
  const { userMenu }: { userMenu: IMenu[] } = useSelector(module => (module as { user: { userMenu: IMenu[] } }).user)
  const Intl = useIntl()
  const menu = (
    <Menu>
      <Menu.Item>
        <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
          个人中心
        </a>
      </Menu.Item>
      <Menu.Item>
        <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
          我的班级
        </a>
      </Menu.Item>
      <Menu.Item>
        <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
          设置
        </a>
      </Menu.Item>
      <Menu.Item danger>
        退出登录
      </Menu.Item>
    </Menu>
  );
  let defaultSelectedKey = userMenu.length ? userMenu[0].children![0].name : '';
  function changeLocale() {
    let locale = getLocale();
    if (locale === 'zh-CN') {
      setLocale('en-US', false);
    } else {
      setLocale('zh-CN', false);
    }
  }
  return (
    <Layout className="base-layout" key={userMenu.length}>
      <Button onClick={changeLocale} className={styles.buttons}>{getLocale() === 'zh-CN' ? '英文' : '中文'}</Button>
      <Header className="header">
        <h2>
          <img className={styles.logo} src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1551624718911&di=4a7004f8d71bd8da84d4eadf1b59e689&imgtype=0&src=http%3A%2F%2Fimg105.job1001.com%2Fupload%2Falbum%2F2014-10-15%2F1413365052_95IE3msH.jpg" alt="" />
        </h2>
        <Dropdown overlay={menu}>
          <div>
            <Avatar
              src={<Image src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
            />
            <span>肖金哲</span>
          </div>
        </Dropdown>
      </Header>
      <Layout>
        <Sider width={200} className="site-layout-background">
          {
            <Menu
              mode="inline"
              theme="dark"
              defaultOpenKeys={['sub0']}
              defaultSelectedKeys={['sub'+defaultSelectedKey]}
              style={{ height: '100%', borderRight: 0 }}
            >{
                userMenu.map((item,index) => {
                  return <SubMenu key={'sub'+index} icon={<item.meta.icon />} title={Intl.formatMessage({ id: item.name })}>{
                    item.children?.map(value => {
                      return value.meta.show ? <Menu.Item key={'sub'+value.name}>
                        <Link to={value.path}>{Intl.formatMessage({ id: value.name })}</Link>
                      </Menu.Item> : null
                    })
                  }</SubMenu>
                })
              }
            </Menu>
          }
        </Sider>
        <Layout style={{ padding: '0 24px 24px' }}>
          <Content
            className="site-layout-background"
            style={{
              padding: 24,
              margin: 0,
              minHeight: 280,
            }}
          >{props.children}</Content>
>>>>>>> de54b307166b277708c9f443ac2c9a94aa3cb036
        </Layout>
      </Layout>
    </Layout>
  );
}
export default MainLayout;


